package com.xubeihong.xubeihong;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

@Slf4j
@Component
public class TicketRun4 {

    @Scheduled(cron = "2/1 0 10 * * ?")
    //@Scheduled(cron = "0/1 14 23 * * ?")
    public int getTicket() throws ExecutionException, InterruptedException {
        //System.out.println(new Date()+"执行");
        List<Future> futureList = new ArrayList<>();
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        int i = 3;
        while(i>0){
            i--;
            futureList.add(executorService.submit(new TicketTask2()));
        }
        //Thread.sleep(2000);
        for(Future future:futureList){
            log.info(future.get()+"");
        }
        return 0;
    }

    //@PostConstruct
    public void init() throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        Future future = executorService.submit(new TicketTask());
        System.out.println(future.get()+"");
    }

}
